class GenresController < ApplicationController
  filter_access_to :all

  # GET /genres/id
  # GET /genres/id.xml
  def show
    @genre = Genre.find(params[:id])
    store_location
    session[:edit_mode] = false

    respond_to do |format|
      format.html
      format.xml { render :xml => @genre }
    end

  end

  # GET /genres/edit/id
  # GET /genres/edit/id.xml
  def edit
    @genre = Genre.find(params[:id])
    store_location
    session[:edit_mode] = true

    respond_to do |format|
      format.html
      format.xml { render :xml => @genre }  
    end
  end

  # PUT /genres/id
  def update
    @genre = Genre.find(params[:id])

    respond_to do |format|
      if @genre.update_attributes(params[:genre])
        flash[:notice] = 'Information Updated.'
        format.html { redirect_to(@genre) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @genre.errors, :status => :unprocessable_entity }
      end
    end
  end

  # GET /genres/new
  # GET /genres/new.xml
  def new
    @genre = Genre.new

    if params[:name]
      @genre.name = params[:name]
    end

    respond_to do |format|
      format.html
      format.xml { render :xml => @genre }
    end
  end

  # POST /genres/id
  def create
    @genre = Genre.new(params[:genre])

    respond_to do |format|
      if @genre.save
        format.html {redirect_to(@genre) }
        format.xml  { render :xml => @genre, :status => :created, :location => @genre }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @genre.errors, :status => :unprocessable_entity }
      end
    end
  end

end
